package cn.itcast.web;

import cn.itcast.result.Result;
import cn.itcast.service.UserService;
import cn.itheima.users.dto.UserLoginDTO;
import cn.itheima.users.pojo.User;
import cn.itheima.users.vo.UserLoginVO;
import cn.itheima.users.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/user/user")
@Api(tags = "C端用户相关接口")
@Slf4j
@AllArgsConstructor
public class UserController {

    private UserService userService;


    @GetMapping("/countByTime")
    List<UserReportVO> countByTime(LocalDate begin, LocalDate end){
       return userService.countByTime(begin, end);
    }

    /**
     * 用户端微信登录
     *
     * @param userLoginDTO  微信登录信息
     * @return 用户登录信息
     */
    @ApiOperation("用户端微信登录")
    @PostMapping("/login")
    public Result<UserLoginVO> login(@RequestBody UserLoginDTO userLoginDTO) {
        log.info("用户端微信登录:{}", userLoginDTO);
        UserLoginVO userLoginVO = userService.wxLogin(userLoginDTO);
        return Result.success(userLoginVO);
    }

    @GetMapping("{id}")
    public Result<User> getById(@PathVariable long id){
       return Result.success(userService.getById(id));
    }
}